package com.ljt.yupictureddd.infrastracture.common;

import com.ljt.yupictureddd.infrastracture.exception.ErrorCode;
import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResponse<T> implements Serializable {
//    状态码
    private int code;
//    数据
    private T data;
//    信息
    private String msg;

    /**
     * 简单封装
     */
    public BaseResponse(int code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    /**
     * 进一步封装
     */
    public BaseResponse(int code, T data) {
        this(code, data,"");
    }

    /**
     * 更简单的
     */
    public BaseResponse(T data) {
        this(ErrorCode.SUCCESS.getCode(),data,"");
    }

    /**
     * 有的时候抛出异常，但是还是要返回个结果，所以要写个错误码的
     * @param errorCode
     */
    public BaseResponse(ErrorCode errorCode){
        this(errorCode.getCode(),null, errorCode.getMessage());
    }


}
